package com.wd.jetpack.ui.main

import android.view.View
import com.wd.base.util.Logger
import com.wd.jetpack.R
import com.wd.jetpack.annotation.SingleClick
import com.wd.jetpack.base.BaseActivity
import com.wd.jetpack.databinding.ActivityRemoteBinding
import com.wd.jetpack.helper.exytens.bindLifeCycle
import com.wd.jetpack.ui.viewmodel.RemoteViewModel

/**
 * Retrofit交互<BR>
 *
 * @author w4425
 * @version [V5.9.3, 2021/6/17]
 * @since V5.9.3
 */
class RemoteActivity : BaseActivity<ActivityRemoteBinding>() {
    private val mViewModel: RemoteViewModel by lazy { RemoteViewModel() }
    override fun getLayoutId(): Int {
        return R.layout.activity_remote
    }

    override fun initView() {
        mBinding.vm = mViewModel
    }

    override fun initData() {
    }

    @SingleClick
    override fun onClick(v: View) {
        when (v.id) {
            R.id.btn_connect -> {
                getArticle()
            }
        }
    }

    private fun getArticle() {
        mViewModel.getArticle().doOnSubscribe {
            Logger.i("加载loading 等")
        }.doAfterTerminate {
          Logger.i("结束loading  等")
        }.bindLifeCycle(this)//绑定生命周期
                .subscribe({
                    Logger.i("加载 成功")
                }, {
                    Logger.i("加载 失败")
                })
    }
}